﻿using System;
using Assets.Scripts.GtsScripts;
using UnityEngine;

// Token: 0x020002BF RID: 703
public class FootEffect : MonoBehaviour
{
	// Token: 0x0600103B RID: 4155 RVA: 0x0007735C File Offset: 0x0007555C
	private void Start()
	{
		this.audioSource = base.gameObject.AddComponent<AudioSource>();
		this.audioSource.spatialBlend = 1f;
		this.audioSource.dopplerLevel = 0f;
		this.audioSource.outputAudioMixerGroup = SoundManager.mg_macro;
		this.animat = base.gameObject.GetComponent<Animator>();
		this.leftFoot = this.animat.GetBoneTransform(HumanBodyBones.LeftFoot);
		this.rightFoot = this.animat.GetBoneTransform(HumanBodyBones.RightFoot);
		if (FootEffect.dustPrefab == null)
		{
			FootEffect.dustPrefab = Resources.Load<GameObject>("Particles/StepDust");
		}
		this.giantess = base.GetComponent<Giantess>();
	}

	// Token: 0x0600103C RID: 4156 RVA: 0x0007740C File Offset: 0x0007560C
	public void OnStep(AnimationEvent e)
	{
		this.scale = base.transform.lossyScale.y;
		float magnitude = (e.floatParameter != 0f) ? e.floatParameter : 1f;
		Vector3 vector = (e.intParameter != 0) ? this.rightFoot.position : this.leftFoot.position;
		vector += base.transform.forward * this.destructionRadius * this.scale / 2f;
		float maxDistance = (vector.y - this.giantess.transform.position.y) * 1.25f;
		RaycastHit raycastHit;
		if (Physics.Raycast(vector, Vector3.down, out raycastHit, maxDistance, Layers.gtsWalkableMask))
		{
			vector = raycastHit.point;
		}
		this.DoStep(vector, magnitude, e.intParameter);
	}

	// Token: 0x0600103D RID: 4157 RVA: 0x00077508 File Offset: 0x00075708
	public void DoStep(Vector3 epicenter, float magnitude, int foot)
	{
		this.scale = base.transform.lossyScale.y;
		EventManager.SendEvent(new StepEvent(this.giantess, epicenter, magnitude, foot));
		this.VisualEffect(epicenter, magnitude);
		if (!GlobalPreferences.GtsPlayerBuildingDestruction.value && this.giantess.isPlayer)
		{
			return;
		}
		if (!GlobalPreferences.GtsBuildingDestruction.value && !this.giantess.isPlayer)
		{
			return;
		}
		this.DestructionEffect(epicenter, magnitude);
	}

	// Token: 0x0600103E RID: 4158 RVA: 0x00077594 File Offset: 0x00075794
	private void VisualEffect(Vector3 epicenter, float magnitude)
	{
		if (!GameController.IsMacroMap || (double)magnitude < 0.3)
		{
			return;
		}
		GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(FootEffect.dustPrefab, epicenter, Quaternion.identity);
		this.dustEmitter = gameObject.transform.GetChild(0).GetComponent<ParticleSystem>();
		this.mainModule = this.dustEmitter.main;
		this.shape = this.dustEmitter.shape;
		gameObject.transform.position = epicenter;
		this.mainModule.startSize = this.scale * magnitude * 100f;
		this.shape.radius = this.scale * magnitude * 100f;
		this.dustEmitter.Play();
		UnityEngine.Object.Destroy(gameObject, this.mainModule.duration + this.mainModule.startLifetime.constant);
	}

	// Token: 0x0600103F RID: 4159 RVA: 0x0007767C File Offset: 0x0007587C
	private void DestructionEffect(Vector3 epicenter, float magnitude)
	{
		Collider[] array = Physics.OverlapSphere(epicenter, this.destructionRadius * this.scale, Layers.buildingMask);
		foreach (Collider collider in array)
		{
			IDestructible componentInParent = collider.GetComponentInParent<IDestructible>();
			if (componentInParent != null)
			{
				componentInParent.Destroy(epicenter, this.scale * 1000f, false, false, true);
			}
		}
	}

	// Token: 0x04001503 RID: 5379
	private Giantess giantess;

	// Token: 0x04001504 RID: 5380
	private static GameObject dustPrefab;

	// Token: 0x04001505 RID: 5381
	private Animator animat;

	// Token: 0x04001506 RID: 5382
	private AudioSource audioSource;

	// Token: 0x04001507 RID: 5383
	private float scale;

	// Token: 0x04001508 RID: 5384
	public float destructionRadius = 100f;

	// Token: 0x04001509 RID: 5385
	private Transform leftFoot;

	// Token: 0x0400150A RID: 5386
	private Transform rightFoot;

	// Token: 0x0400150B RID: 5387
	private ParticleSystem dustEmitter;

	// Token: 0x0400150C RID: 5388
	private ParticleSystem.MainModule mainModule;

	// Token: 0x0400150D RID: 5389
	private ParticleSystem.ShapeModule shape;
}
